<?php
 require_once("request.php");
 require_once("sql.php");
 $code = $_GET["code"];
 function getUserInfo($code){
 	$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx3babaf2c7f48c3d2&secret=198c5f5866b3f2fffcdc3400f5014354&code={$code}&grant_type=authorization_code";
 	$response = httpGet($url);
    //echo $response;
 	$responseObj = json_decode($response);
    //access_token
 	$access_token = $responseObj->access_token;
 	//过期时间
 	$expires_time = time() + $responseObj->expires_in - 200;

 	//用户openid
 	$openid = $responseObj->openid;
 	//拉去用户信息
    $url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}";
    $response1 = httpGet($url);
    return $response1;
 }

 $object = json_decode(getUserInfo($code));

if(select($object->openid) == NULL){
 	insert($object->nickname,$object->openid,$object->headimgurl);
 }
 ?>
